
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/** 
* @author leejun.happy@gmail.com 
* @date 2017年7月17日 上午9:49:24 
* @describe 
*/

public class TankControl extends KeyAdapter {
	
	public Tank model = null;
	public static List<Tank> tanks = new ArrayList<Tank>();
	public static List<Shell> shells = new ArrayList<Shell>();
	Random r = new Random();
	
	public TankControl(Tank model) {
		for (int i = 0; i < 10; i++) {
			Tank t = new Tank(r.nextInt(300), r.nextInt(200));
			t.good = false;
			t.dir = Direction.R;
			tanks.add(t);
		}
		this.model = model;
	}

	@Override
	public void keyPressed(KeyEvent e) {
		int key = e.getKeyCode();
		if (key == KeyEvent.VK_A) {
			model.setDir(Direction.L);
		} else if (key == KeyEvent.VK_W) {
			model.setDir(Direction.U);
		} else if (key == KeyEvent.VK_D) {
			model.setDir(Direction.R);
		} else if (key == KeyEvent.VK_S) {
			model.setDir(Direction.D);
		} else if (key == KeyEvent.VK_P) {
			model.fire();
		} else if (key == KeyEvent.VK_O) {
			model.live = true;
		} else if (key == KeyEvent.VK_L) {
			Tank.paused = !Tank.paused;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		int key = e.getKeyCode();
		if (key == KeyEvent.VK_A) {
			model.setDir(Direction.STOP);
		} else if (key == KeyEvent.VK_W) {
			model.setDir(Direction.STOP);
		} else if (key == KeyEvent.VK_D) {
			model.setDir(Direction.STOP);
		} else if (key == KeyEvent.VK_S) {
			model.setDir(Direction.STOP);
		}
		
	}
	
	

}
